<template>
  <div>
    <van-nav-bar
      fixed
      placeholder
      safe-area-inset-top
      title="全网获客"
      @click-left="back"
    >
      <template #left>
        <van-icon name="arrow-left" size="16px" color="#333" />
      </template>
    </van-nav-bar>
    <div>
      <div style="width: 100vw">
        <img src="@/assets/customer.png" alt="" width="100%" />
      </div>
    </div>
    <div class="customerList">
      <div v-for="(item, index) in customerList" :key="index">
        <div>
          <div>
            <van-icon
              name="manager"
              size="15px"
              style="vertical-align: text-top; margin-right: 3px"
            />
            <span>{{ item.mobile }}</span>
          </div>
          <div style="font-size: 12px; color: #666; margin-top: 5px">
            {{ item.created_at }}
          </div>
        </div>
        <div>
          <van-icon
            size="20px"
            name="phone-o"
            @click="call(item)"
            :style="{ color: item.is_call == 1 ? '#46b8cb' : '' }"
            style="transform: translateX(-10px)"
          />
        </div>
      </div>
    </div>
    <div v-if="customerList.length == 0" class="nohouse">
      <img src="../../assets/nohouse.png" alt="" />
      <div>暂无客源信息</div>
    </div>
    <div class="slot"></div>
    <div class="bottom">
      <div>*数据为全网抓取的潜客数据(来源地域以注册时为准)</div>
      <div>*数据每日更新 数量不定</div>
      <div>*用户最终需求待确认（租售）</div>
    </div>
  </div>
</template>

<script>
import { recommendList } from "@/apis/user";
export default {
  data() {
    return {
      currentPage: 1,
      customerList: [],
      color: "",
      loading: true,
    };
  },
  created() {
    this.getCustomerList();
  },
  // mounted() {
  //   window.addEventListener("scroll", this.showScroll);
  // },
  beforeUpdate() {
    window.addEventListener("scroll", this.showScroll);
  },
  destroyed() {
    window.removeEventListener("scroll", this.showScroll);
  },
  methods: {
    call(e) {
      console.log(e);
      if (e.is_call == 1) {
        window.location.href = `tel:${e.mobile}`;
      } else {
        this.$dialog
          .confirm({
            title: "温馨提示",
            className: "leftpart",
            confirmButtonText: "购买会员",
            confirmButtonColor: "#45b7cb",
            cancelButtonText: "取消",
            message: "购买会员后即可留存客源信息及拨打电话",
            messageAlign: "left",
          })
          .then(() => {
            this.$router.push("/buyjoin");
          })
          .catch(() => {});
      }
    },
    getCustomerList() {
      recommendList({
        currentPage: this.currentPage,
        perPage: 15,
      }).then((res) => {
        console.log("recommendList", res);
        if (res.code == 200 || res.code == 201) {
          this.customerList = this.customerList.concat(res.result);
          if (res.result.length != 15) {
            this.loading = false;
          }
        }
      });
    },
    showScroll() {
      const scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;
      const windowHeight =
        document.documentElement.clientHeight || document.body.clientHeight;
      const scrollHeight =
        document.documentElement.scrollHeight || document.body.scrollHeight;
      if (scrollTop + windowHeight >= scrollHeight - 20 && this.loading) {
        this.currentPage++;
        this.getCustomerList();
      }
    },
    back() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="less" scoped>
.nohouse {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  img {
    margin-top: 20px;
    width: 100px;
  }
  div {
    font-size: 16px;
    color: #333;
    font-weight: bold;
    margin-top: 20px;
  }
}
.slot {
  height: 72px;
}
.bottom {
  font-size: 12px;
  color: rgba(51, 51, 51, 0.486);
  background-color: #eef7fe;
  box-sizing: border-box;
  padding: 5px 15px;
  position: fixed;
  bottom: 0;
  width: 100vw;
  & > div {
    margin: 5px 0;
  }
}
.customerList {
  margin: 20px 15px;
  & > div:last-child {
    margin-bottom: 0 !important;
  }
  & > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    font-size: 15px;
  }
}
</style>